(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

diff(x, y) → cond1(equal(x, y), x, y)
cond1(true, x, y) → 0
cond1(false, x, y) → cond2(gt(x, y), x, y)
cond2(true, x, y) → s(diff(x, s(y)))
cond2(false, x, y) → s(diff(s(x), y))
gt(0, v) → false
gt(s(u), 0) → true
gt(s(u), s(v)) → gt(u, v)
equal(0, 0) → true
equal(s(x), 0) → false
equal(0, s(y)) → false
equal(s(x), s(y)) → equal(x, y)

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, n^2).


The TRS R consists of the following rules:

diff(x, y) → cond1(equal(x, y), x, y) [1]
cond1(true, x, y) → 0 [1]
cond1(false, x, y) → cond2(gt(x, y), x, y) [1]
cond2(true, x, y) → s(diff(x, s(y))) [1]
cond2(false, x, y) → s(diff(s(x), y)) [1]
gt(0, v) → false [1]
gt(s(u), 0) → true [1]
gt(s(u), s(v)) → gt(u, v) [1]
equal(0, 0) → true [1]
equal(s(x), 0) → false [1]
equal(0, s(y)) → false [1]
equal(s(x), s(y)) → equal(x, y) [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

diff(x, y) → cond1(equal(x, y), x, y) [1]
cond1(true, x, y) → 0 [1]
cond1(false, x, y) → cond2(gt(x, y), x, y) [1]
cond2(true, x, y) → s(diff(x, s(y))) [1]
cond2(false, x, y) → s(diff(s(x), y)) [1]
gt(0, v) → false [1]
gt(s(u), 0) → true [1]
gt(s(u), s(v)) → gt(u, v) [1]
equal(0, 0) → true [1]
equal(s(x), 0) → false [1]
equal(0, s(y)) → false [1]
equal(s(x), s(y)) → equal(x, y) [1]

The TRS has the following type information:
diff :: 0:s → 0:s → 0:s
cond1 :: true:false → 0:s → 0:s → 0:s
equal :: 0:s → 0:s → true:false
true :: true:false
0 :: 0:s
false :: true:false
cond2 :: true:false → 0:s → 0:s → 0:s
gt :: 0:s → 0:s → true:false
s :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:
none

And the following fresh constants: none

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

diff(x, y) → cond1(equal(x, y), x, y) [1]
cond1(true, x, y) → 0 [1]
cond1(false, x, y) → cond2(gt(x, y), x, y) [1]
cond2(true, x, y) → s(diff(x, s(y))) [1]
cond2(false, x, y) → s(diff(s(x), y)) [1]
gt(0, v) → false [1]
gt(s(u), 0) → true [1]
gt(s(u), s(v)) → gt(u, v) [1]
equal(0, 0) → true [1]
equal(s(x), 0) → false [1]
equal(0, s(y)) → false [1]
equal(s(x), s(y)) → equal(x, y) [1]

The TRS has the following type information:
diff :: 0:s → 0:s → 0:s
cond1 :: true:false → 0:s → 0:s → 0:s
equal :: 0:s → 0:s → true:false
true :: true:false
0 :: 0:s
false :: true:false
cond2 :: true:false → 0:s → 0:s → 0:s
gt :: 0:s → 0:s → true:false
s :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

true => 1
0 => 0
false => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

cond1(z, z', z'') -{ 1 }→ cond2(gt(x, y), x, y) :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
cond1(z, z', z'') -{ 1 }→ 0 :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
cond2(z, z', z'') -{ 1 }→ 1 + diff(x, 1 + y) :|: z' = x, z'' = y, z = 1, x >= 0, y >= 0
cond2(z, z', z'') -{ 1 }→ 1 + diff(1 + x, y) :|: z' = x, z'' = y, x >= 0, y >= 0, z = 0
diff(z, z') -{ 1 }→ cond1(equal(x, y), x, y) :|: x >= 0, y >= 0, z = x, z' = y
equal(z, z') -{ 1 }→ equal(x, y) :|: z' = 1 + y, x >= 0, y >= 0, z = 1 + x
equal(z, z') -{ 1 }→ 1 :|: z = 0, z' = 0
equal(z, z') -{ 1 }→ 0 :|: x >= 0, z = 1 + x, z' = 0
equal(z, z') -{ 1 }→ 0 :|: z' = 1 + y, y >= 0, z = 0
gt(z, z') -{ 1 }→ gt(u, v) :|: v >= 0, z' = 1 + v, z = 1 + u, u >= 0
gt(z, z') -{ 1 }→ 1 :|: z = 1 + u, z' = 0, u >= 0
gt(z, z') -{ 1 }→ 0 :|: v >= 0, z' = v, z = 0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V4),0,[diff(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V4),0,[cond1(V, V1, V4, Out)],[V >= 0,V1 >= 0,V4 >= 0]).
eq(start(V, V1, V4),0,[cond2(V, V1, V4, Out)],[V >= 0,V1 >= 0,V4 >= 0]).
eq(start(V, V1, V4),0,[gt(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(start(V, V1, V4),0,[equal(V, V1, Out)],[V >= 0,V1 >= 0]).
eq(diff(V, V1, Out),1,[equal(V2, V3, Ret0),cond1(Ret0, V2, V3, Ret)],[Out = Ret,V2 >= 0,V3 >= 0,V = V2,V1 = V3]).
eq(cond1(V, V1, V4, Out),1,[],[Out = 0,V1 = V5,V4 = V6,V = 1,V5 >= 0,V6 >= 0]).
eq(cond1(V, V1, V4, Out),1,[gt(V7, V8, Ret01),cond2(Ret01, V7, V8, Ret1)],[Out = Ret1,V1 = V7,V4 = V8,V7 >= 0,V8 >= 0,V = 0]).
eq(cond2(V, V1, V4, Out),1,[diff(V9, 1 + V10, Ret11)],[Out = 1 + Ret11,V1 = V9,V4 = V10,V = 1,V9 >= 0,V10 >= 0]).
eq(cond2(V, V1, V4, Out),1,[diff(1 + V11, V12, Ret12)],[Out = 1 + Ret12,V1 = V11,V4 = V12,V11 >= 0,V12 >= 0,V = 0]).
eq(gt(V, V1, Out),1,[],[Out = 0,V13 >= 0,V1 = V13,V = 0]).
eq(gt(V, V1, Out),1,[],[Out = 1,V = 1 + V14,V1 = 0,V14 >= 0]).
eq(gt(V, V1, Out),1,[gt(V15, V16, Ret2)],[Out = Ret2,V16 >= 0,V1 = 1 + V16,V = 1 + V15,V15 >= 0]).
eq(equal(V, V1, Out),1,[],[Out = 1,V = 0,V1 = 0]).
eq(equal(V, V1, Out),1,[],[Out = 0,V17 >= 0,V = 1 + V17,V1 = 0]).
eq(equal(V, V1, Out),1,[],[Out = 0,V1 = 1 + V18,V18 >= 0,V = 0]).
eq(equal(V, V1, Out),1,[equal(V19, V20, Ret3)],[Out = Ret3,V1 = 1 + V20,V19 >= 0,V20 >= 0,V = 1 + V19]).
input_output_vars(diff(V,V1,Out),[V,V1],[Out]).
input_output_vars(cond1(V,V1,V4,Out),[V,V1,V4],[Out]).
input_output_vars(cond2(V,V1,V4,Out),[V,V1,V4],[Out]).
input_output_vars(gt(V,V1,Out),[V,V1],[Out]).
input_output_vars(equal(V,V1,Out),[V,V1],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. recursive : [equal/3]
1. recursive : [gt/3]
2. recursive : [cond1/4,cond2/4,diff/3]
3. non_recursive : [start/3]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into equal/3
1. SCC is partially evaluated into gt/3
2. SCC is partially evaluated into diff/3
3. SCC is partially evaluated into start/3

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations equal/3
* CE 19 is refined into CE [20]
* CE 17 is refined into CE [21]
* CE 18 is refined into CE [22]
* CE 16 is refined into CE [23]


### Cost equations --> "Loop" of equal/3
* CEs [21] --> Loop 13
* CEs [22] --> Loop 14
* CEs [23] --> Loop 15
* CEs [20] --> Loop 16

### Ranking functions of CR equal(V,V1,Out)
* RF of phase [16]: [V,V1]

#### Partial ranking functions of CR equal(V,V1,Out)
* Partial RF of phase [16]:
- RF of loop [16:1]:
V
V1


### Specialization of cost equations gt/3
* CE 12 is refined into CE [24]
* CE 11 is refined into CE [25]
* CE 10 is refined into CE [26]


### Cost equations --> "Loop" of gt/3
* CEs [25] --> Loop 17
* CEs [26] --> Loop 18
* CEs [24] --> Loop 19

### Ranking functions of CR gt(V,V1,Out)
* RF of phase [19]: [V,V1]

#### Partial ranking functions of CR gt(V,V1,Out)
* Partial RF of phase [19]:
- RF of loop [19:1]:
V
V1


### Specialization of cost equations diff/3
* CE 14 is refined into CE [27,28]
* CE 15 is refined into CE [29,30]
* CE 13 is refined into CE [31,32]


### Cost equations --> "Loop" of diff/3
* CEs [32] --> Loop 20
* CEs [31] --> Loop 21
* CEs [28] --> Loop 22
* CEs [30] --> Loop 23
* CEs [27] --> Loop 24
* CEs [29] --> Loop 25

### Ranking functions of CR diff(V,V1,Out)
* RF of phase [22]: [V-V1]
* RF of phase [23]: [-V+V1]

#### Partial ranking functions of CR diff(V,V1,Out)
* Partial RF of phase [22]:
- RF of loop [22:1]:
V-V1
* Partial RF of phase [23]:
- RF of loop [23:1]:
-V+V1


### Specialization of cost equations start/3
* CE 2 is refined into CE [33]
* CE 6 is refined into CE [34,35,36,37,38]
* CE 3 is refined into CE [39,40,41,42]
* CE 4 is refined into CE [43,44,45,46,47,48]
* CE 5 is refined into CE [49,50,51,52,53]
* CE 7 is refined into CE [54,55,56,57,58,59,60,61]
* CE 8 is refined into CE [62,63,64,65]
* CE 9 is refined into CE [66,67,68,69,70,71]


### Cost equations --> "Loop" of start/3
* CEs [60,65,70] --> Loop 26
* CEs [59,61,64,69,71] --> Loop 27
* CEs [33,36,37,38] --> Loop 28
* CEs [34,35,57,58,63,68] --> Loop 29
* CEs [41] --> Loop 30
* CEs [47] --> Loop 31
* CEs [46,51] --> Loop 32
* CEs [40,50] --> Loop 33
* CEs [39,55] --> Loop 34
* CEs [42,43,44,45,48,49,52,53,54,56,62,66,67] --> Loop 35

### Ranking functions of CR start(V,V1,V4)

#### Partial ranking functions of CR start(V,V1,V4)


Computing Bounds
=====================================

#### Cost of chains of equal(V,V1,Out):
* Chain [[16],15]: 1*it(16)+1
Such that:it(16) =< V

with precondition: [Out=1,V=V1,V>=1]

* Chain [[16],14]: 1*it(16)+1
Such that:it(16) =< V

with precondition: [Out=0,V>=1,V1>=V+1]

* Chain [[16],13]: 1*it(16)+1
Such that:it(16) =< V1

with precondition: [Out=0,V1>=1,V>=V1+1]

* Chain [15]: 1
with precondition: [V=0,V1=0,Out=1]

* Chain [14]: 1
with precondition: [V=0,Out=0,V1>=1]

* Chain [13]: 1
with precondition: [V1=0,Out=0,V>=1]


#### Cost of chains of gt(V,V1,Out):
* Chain [[19],18]: 1*it(19)+1
Such that:it(19) =< V

with precondition: [Out=0,V>=1,V1>=V]

* Chain [[19],17]: 1*it(19)+1
Such that:it(19) =< V1

with precondition: [Out=1,V1>=1,V>=V1+1]

* Chain [18]: 1
with precondition: [V=0,Out=0,V1>=0]

* Chain [17]: 1
with precondition: [V1=0,Out=1,V>=1]


#### Cost of chains of diff(V,V1,Out):
* Chain [[23],20]: 5*it(23)+1*s(1)+2*s(6)+3
Such that:it(23) =< Out
aux(3) =< V1
s(1) =< aux(3)
s(7) =< it(23)*aux(3)
s(6) =< s(7)

with precondition: [Out+V=V1,V>=1,V1>=V+1]

* Chain [[22],20]: 5*it(22)+1*s(1)+2*s(12)+3
Such that:it(22) =< Out
aux(6) =< V1+Out
s(1) =< aux(6)
s(13) =< it(22)*aux(6)
s(12) =< s(13)

with precondition: [V=Out+V1,V1>=1,V>=V1+1]

* Chain [25,[23],20]: 6*it(23)+2*s(6)+8
Such that:aux(7) =< Out
it(23) =< aux(7)
s(7) =< it(23)*aux(7)
s(6) =< s(7)

with precondition: [V=0,V1=Out,V1>=2]

* Chain [25,20]: 1*s(1)+8
Such that:s(1) =< 1

with precondition: [V=0,V1=1,Out=1]

* Chain [24,[22],20]: 6*it(22)+2*s(12)+8
Such that:aux(8) =< Out
it(22) =< aux(8)
s(13) =< it(22)*aux(8)
s(12) =< s(13)

with precondition: [V1=0,V=Out,V>=2]

* Chain [24,20]: 1*s(1)+8
Such that:s(1) =< 1

with precondition: [V=1,V1=0,Out=1]

* Chain [21]: 3
with precondition: [V=0,V1=0,Out=0]

* Chain [20]: 1*s(1)+3
Such that:s(1) =< V1

with precondition: [Out=0,V1=V,V1>=1]


#### Cost of chains of start(V,V1,V4):
* Chain [35]: 9*s(14)+5*s(15)+8*s(17)+2*s(19)+3*s(20)+2*s(26)+10*s(28)+4*s(32)+5*s(34)+1*s(36)+2*s(38)+2*s(47)+11
Such that:s(35) =< V1+1
s(15) =< V1-V4
s(34) =< V1-V4+1
aux(10) =< 1
aux(11) =< -V1+V4
aux(12) =< V1
aux(13) =< V4
s(20) =< aux(10)
s(28) =< aux(11)
s(17) =< aux(12)
s(14) =< aux(13)
s(31) =< s(28)*aux(13)
s(32) =< s(31)
s(18) =< s(15)*aux(12)
s(19) =< s(18)
s(46) =< s(17)*aux(12)
s(47) =< s(46)
s(36) =< s(35)
s(37) =< s(34)*s(35)
s(38) =< s(37)
s(25) =< s(14)*aux(13)
s(26) =< s(25)

with precondition: [V=0,V1>=0]

* Chain [34]: 10
with precondition: [V=0,V1=1]

* Chain [33]: 6*s(50)+2*s(54)+6*s(56)+2*s(58)+9
Such that:aux(15) =< V1
s(55) =< V1+1
s(50) =< aux(15)
s(53) =< s(50)*aux(15)
s(54) =< s(53)
s(56) =< s(55)
s(57) =< s(56)*s(55)
s(58) =< s(57)

with precondition: [V=0,V4=0,V1>=1]

* Chain [32]: 2*s(59)+1*s(61)+6
Such that:s(61) =< V1+1
aux(16) =< V4
s(59) =< aux(16)

with precondition: [V=0,V1+1=V4,V1>=0]

* Chain [31]: 1*s(62)+5*s(63)+1*s(65)+2*s(67)+6
Such that:s(63) =< 1
s(62) =< V4
s(64) =< V4+1
s(65) =< s(64)
s(66) =< s(63)*s(64)
s(67) =< s(66)

with precondition: [V=0,V1=V4,V1>=1]

* Chain [30]: 1*s(68)+1*s(69)+6
Such that:s(68) =< V4
s(69) =< V4+1

with precondition: [V=0,V1=V4+1,V1>=2]

* Chain [29]: 2*s(70)+6*s(72)+2*s(74)+6*s(77)+2*s(79)+9
Such that:s(76) =< V
s(71) =< V4+1
aux(17) =< 1
s(70) =< aux(17)
s(77) =< s(76)
s(78) =< s(77)*s(76)
s(79) =< s(78)
s(72) =< s(71)
s(73) =< s(72)*s(71)
s(74) =< s(73)

with precondition: [V1=0,V>=1]

* Chain [28]: 2*s(80)+5*s(81)+1*s(83)+2*s(85)+5*s(86)+2*s(90)+4
Such that:s(86) =< -V1+V4+1
s(82) =< V1
s(81) =< V1-V4
aux(18) =< V4+1
s(80) =< aux(18)
s(89) =< s(86)*aux(18)
s(90) =< s(89)
s(83) =< s(82)
s(84) =< s(81)*s(82)
s(85) =< s(84)

with precondition: [V=1,V1>=0,V4>=0]

* Chain [27]: 3*s(91)+5*s(92)+2*s(96)+2*s(97)+3
Such that:s(92) =< -V+V1
aux(19) =< V
aux(20) =< V1
s(97) =< aux(19)
s(91) =< aux(20)
s(95) =< s(92)*aux(20)
s(96) =< s(95)

with precondition: [V>=1,V1>=V]

* Chain [26]: 5*s(100)+1*s(102)+2*s(104)+2*s(105)+3
Such that:s(101) =< V
s(100) =< V-V1
aux(21) =< V1
s(105) =< aux(21)
s(102) =< s(101)
s(103) =< s(100)*s(101)
s(104) =< s(103)

with precondition: [V1>=1,V>=V1+1]


Closed-form bounds of start(V,V1,V4):
-------------------------------------
* Chain [35] with precondition: [V=0,V1>=0]
- Upper bound: 8*V1+14+2*V1*V1+2*V1*nat(V1-V4)+nat(V4)*9+nat(V4)*2*nat(V4)+nat(V4)*4*nat(-V1+V4)+ (V1+1)+ (2*V1+2)*nat(V1-V4+1)+nat(-V1+V4)*10+nat(V1-V4+1)*5+nat(V1-V4)*5
- Complexity: n^2
* Chain [34] with precondition: [V=0,V1=1]
- Upper bound: 10
- Complexity: constant
* Chain [33] with precondition: [V=0,V4=0,V1>=1]
- Upper bound: 6*V1+9+2*V1*V1+ (6*V1+6)+ (2*V1+2)* (V1+1)
- Complexity: n^2
* Chain [32] with precondition: [V=0,V1+1=V4,V1>=0]
- Upper bound: V1+2*V4+7
- Complexity: n
* Chain [31] with precondition: [V=0,V1=V4,V1>=1]
- Upper bound: 4*V4+14
- Complexity: n
* Chain [30] with precondition: [V=0,V1=V4+1,V1>=2]
- Upper bound: 2*V4+7
- Complexity: n
* Chain [29] with precondition: [V1=0,V>=1]
- Upper bound: 6*V+11+2*V*V+nat(V4+1)*6+nat(V4+1)*2*nat(V4+1)
- Complexity: n^2
* Chain [28] with precondition: [V=1,V1>=0,V4>=0]
- Upper bound: V1+4+2*V1*nat(V1-V4)+ (2*V4+2)+ (2*V4+2)*nat(-V1+V4+1)+nat(-V1+V4+1)*5+nat(V1-V4)*5
- Complexity: n^2
* Chain [27] with precondition: [V>=1,V1>=V]
- Upper bound: 2*V+3*V1+3+ (-V+V1)* (2*V1)+ (-5*V+5*V1)
- Complexity: n^2
* Chain [26] with precondition: [V1>=1,V>=V1+1]
- Upper bound: 5*V-5*V1+ (V+3+ (V-V1)* (2*V)+2*V1)
- Complexity: n^2

### Maximum cost of start(V,V1,V4): max([max([max([max([2*V1*nat(-V+V1)+2*V+nat(-V+V1)*5,3*V1+6+2*V1*V1+ (V1+1)+max([5*V1+5+ (2*V1+2)* (V1+1),2*V1+5+2*V1*nat(V1-V4)+nat(V4)*9+nat(V4)*2*nat(V4)+nat(V4)*4*nat(-V1+V4)+ (2*V1+2)*nat(V1-V4+1)+nat(-V1+V4)*10+nat(V1-V4+1)*5+nat(V1-V4)*5])])+V1,2*V*nat(V-V1)+V+nat(V-V1)*5])+V1,2*V1*nat(V1-V4)+1+nat(V4+1)*2+nat(V4+1)*2*nat(-V1+V4+1)+nat(-V1+V4+1)*5+nat(V1-V4)*5])+V1,max([nat(V4)+max([V1+1+nat(V4),nat(V4+1)*2+5+nat(V4+1)]),6*V+1+2*V*V+nat(V4+1)*6+nat(V4+1)*2*nat(V4+1)+4])+3])+3
Asymptotic class: n^2
* Total analysis performed in 504 ms.

(10) BOUNDS(1, n^2)